package com.sp.fresh_produce.controller;

import com.github.pagehelper.PageInfo;
import com.sp.fresh_produce.common.GenericReturnApiObject;
import com.sp.fresh_produce.controller.dto.req.ProductListReq;
import com.sp.fresh_produce.model.pojo.Product;
import com.sp.fresh_produce.service.AdminProduceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *  前台商品模块
 */
@RestController
@Tag(name = "Product", description = "前台商品模块")
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private AdminProduceService adminProduceService;

    /**
     *  商品详情
     */
    @Operation(summary = "商品详情")
    @GetMapping("/detail")
    public GenericReturnApiObject getProductDetail(@RequestParam Integer id) {
        Product productDetail = adminProduceService.getProductDetail(id);
        return GenericReturnApiObject.success(productDetail);
    }

    /**
     *
     * 商品列表
     */
    @Operation(summary = "商品列表")
    @GetMapping("/list")
    public GenericReturnApiObject list(ProductListReq productListReq) {
        PageInfo list = adminProduceService.list(productListReq);
        return GenericReturnApiObject.success(list);
    }
}
